﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace PotentialRentals.Models
{
    public class Rental
    {
        [Key]
        public int RentalId { get; set; }

        [StringLength(50)]
        [Display(Name = "Rental Name: ")]
        public string Name { get; set; }

        [RegularExpression("((\\(\\d{3}\\) ?)|(\\d{3}-))?\\d{3}-\\d{4}", ErrorMessage = "Invalid Phone")]
        [DisplayFormat(DataFormatString = "{0:###-###-####}")]
        [StringLength(12)]
        [Display(Name = "Phone: ")]
        public string Phone { get; set; }

        [RegularExpression("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$", ErrorMessage = "Incorrect Email")]
        [StringLength(50)]
        [Display(Name = "Email: ")]
        public string Email { get; set; }

        [Required]
        [Range(0, 50000, ErrorMessage = "Your rent shouldn't be this high")]
        [Display(Name = "*Rent: ")]
        public int Rent { get; set; }

        [Range(0, 50000, ErrorMessage = "Your deposit shouldn't be this high")]
        [Display(Name = "Deposit: ")]
        public int Deposit { get; set; }

        [Range(0, 10, ErrorMessage = "Lets keep the bedrooms reasonable")]
        [Required(ErrorMessage = "Bedrooms are required")]
        [Display(Name = "Bedrooms: ")]
        public int Bedrooms { get; set; }

        [Range(0, 10, ErrorMessage = "Lets keep the bathrooms reasonable")]
        [Required(ErrorMessage = "Bathrooms are required")]
        [DisplayFormat(DataFormatString = "{0:0.##}")]
        [Display(Name = "Bathrooms: ")]
        public double Bathrooms { get; set; }

        public virtual Address Address { get; set; }

        public virtual User Owner { get; set; }

        [ForeignKey("Owner")]
        public int OwnerId { get; set; }

        [Display(Name = "Rental Type: ")]
        public virtual RentType Type { get; set; }

        [Display(Name="Rental Amenities: ")]
        public virtual ICollection<RentalAmenity> Amenities { get; set; }

        public virtual UserRentalRank UserRank { get; set; }

        public virtual ICollection<User> Users { get; set; }

        public Rental()
        {
            Amenities = new List<RentalAmenity>();
        }
    }
}